﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>应用程序文件版本管理</title>
    <style type="text/css">
        *{padding:0px;margin:0px;list-style-type:none;}
    </style>
    <script type="text/javascript" src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">

        function createApp() {
            var appName = $("#newAppName").val();
            if (appName) {
                $.ajax({
                    url: "/home/createApp",
                    type: "post",
                    data: "appName=" + appName,
                    success: function (data) {
                        if (data == 'ok') {
                            location.href = '/home/index';
                        } else {
                            alert(data);
                        }
                    },
                    error: function (request) {
                        alert("请求失败");
                    }
                });
            } else {
                alert("请输入应用程序名称");
            }
        }

        function scanAppPath(appID) {
            if (appID > 0) {
                $.ajax({
                    url: "/home/scanAppPath",
                    type: "post",
                    data: "id=" + appID,
                    success: function (data) {
                        if (isNaN(data)) {
                            alert(data);
                        } else {
                            if (data >= 0) {
                                alert("已经扫描到" + data + "个新文件");
                            } else {
                                alert("扫描失败");
                            }
                        }
                    },
                    error: function (request) {
                        alert("请求失败");
                    }
                });
            }
        }

        function save(id) {
            var ver = $("#AppVersion" + id).val();
            var state = $("#AppState" + id).val();
            var des = $("#descrption" + id).val();
            $.ajax({
                url: "/home/saveAppInfo",
                type: "post",
                data: "id=" + id + "&AppVersion=" + ver + "&AppState=" + state + "&descrption=" + des,
                success: function (data) {
                    if (data > 0) {
                        location.href = "/home/index";
                    } else {
                        alert("未修改数据");
                    }
                },
                error: function (request) {
                    alert("请求失败");
                }
            });
        }
    </script>
</head>
<body>
    <div style="width:80%;margin:0px auto 0px;min-height:50px;line-height:50px;text-align:center;">
        <input type="text" id="newAppName" placeholder="请输入应用程序名称" />&emsp;
        <input type="button" value="创建" onclick="createApp()" />
    </div>

    <div style="width:80%;margin:0px auto 0px;"> 
        <table style="width:100%;">
            <tr>
                <td>编号</td>
                <td>应用程序名称</td>
                <td>应用程序版本</td>
                <td>应用程序状态</td>
                <td>描述</td>
                <td>操作</td>
            </tr>

            @{ 
                if (ViewData["apps"] != null)
                {
                    var list = (List<AutoUpdateServer.Models.AppNames>)ViewData["apps"];
                    if (list != null && list.Count > 0)
                    {
                        foreach (var item in list)
                        {
                            <tr>
                                <td>@item.id</td>
                                <td>@item.AppName</td>
                                <td><input type="number" name="AppVersion" id="AppVersion@(item.id)" value="@item.AppVersion" /> </td>
                                <td>
                                    <select id="AppState@(item.id)" name="AppState">
                                        <option value="自动更新" @{if (item.AppState.Equals("自动更新")){ <text>selected="selected" </text>}} >自动更新</option>
                                        <option value="停止更新" @{if (item.AppState.Equals("停止更新")){ <text>selected="selected" </text>}} >停止更新</option>
                                    </select>
                                </td>
                                <td><input type="text" name="descrption" id="descrption@(item.id)" value="@item.descrption" /> </td>
                                <td>
                                    <input type="button" value="扫描" onclick="scanAppPath('@item.id')" />
                                    <input type="button" value="查看" onclick="javascript: window.open('/home/fileList/@item.id','_blank')" />
                                    <input type="button" value="保存" onclick="save('@item.id')"/>
                                </td>
                            </tr>
                        }
                    }
                }
            }

        </table>
    </div>
</body>
</html>
